package com.doge.controller.admin.promotion;

import com.doge.bean.base.BaseData;
import com.doge.bean.base.BaseParam;
import com.doge.bean.base.BaseRespVo;
import com.doge.bean.pojo.ad.Ad;
import com.doge.service.admin.promotion.AdService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * promotion包里面全是推广模块相关的
 * AdController负责的是广告模块的管理
 * Created By ntian
 */
@RestController
@RequestMapping("admin/ad")
public class AdController {
    /**
     * 将AdService注册，广告管理
     */
    @Autowired
    AdService adService;

    /**GET
     * /admin/ad/list?page=1&limit=20&name=标题&content=内容&sort=add_time&order=desc
     * sort代表的是按照列名排序
     * order代表的是逆序，还是顺序
     */
    @GetMapping("list")
    public BaseRespVo adList(String name, String content,BaseParam baseParam){
        BaseData data = adService.listAllAds(name,content,baseParam);
        return BaseRespVo.ok(data);
    }

    /**
     * POST
     * 	http://182.92.235.201:8083/admin/ad/create
     */
    @PostMapping("create")
    public BaseRespVo createAdList(@RequestBody Ad ad){
        int rows = adService.createAdList(ad);
        return BaseRespVo.ok(rows);
    }

    /**
     * POST	http://182.92.235.201:8083/admin/ad/update
     */

    @PostMapping("update")
    public BaseRespVo updateAd(@RequestBody Ad ad){
        int rows = adService.updateAd(ad);
        return BaseRespVo.ok(rows);
    }

    /**
     * POST http://182.92.235.201:8083/admin/ad/delete
     */
    @PostMapping("delete")
    public BaseRespVo deleteAd(@RequestBody Ad ad){
        int rows = adService.deleteAd(ad);
        return BaseRespVo.ok(rows);
    }








}